﻿using System;
using System.Collections.Generic;
using Ue.Eagle.Runtime.Configuration;


namespace Ue.Eagle.Runtime.Models
{
    public class PluginExtension
    {
        //private Func<string,PluginExtensionPoint> acquireExtensionPoint;
        private PluginExtensionElement extensionElement;

        //public PluginExtension(Func<string,PluginExtensionPoint> acquireExtensionPoint, PluginExtensionElement extensionElement)
        public PluginExtension(PluginExtensionElement extensionElement)
        {
            //this.acquireExtensionPoint = acquireExtensionPoint;

            this.extensionElement = extensionElement;
            //注意必须在这里赋值，不然XmlReader读过之后将读不到值。
            this.PointId = extensionElement.PointId;

        }

        public string PointId { get; private set; }

        /// <summary>
        /// 当前所扩展的扩展点
        /// </summary>
        //public PluginExtensionPoint ExtensionPoint 
        //{
        //    get { return this.acquireExtensionPoint(this.PointId); }
        //}

        /// <summary>
        /// 扩展点扩展配置
        /// </summary>
        public PluginExtensionElement GetExtensionElement(Func<string, PluginExtensionPoint> acquirePointByPointId)
        {
            var point = acquirePointByPointId(this.PointId);
            if (point == null)
            {
                return null;
            }

            return this.extensionElement.DeserializeExtensionElement(pointId => this.PointId.Equals(pointId) ? point.ExtensionElementType : null);
        }


    
    }
}
